package com.example.servlet;


import com.example.Service.CommentService;
import com.example.Service.NewsService;
import com.example.pojo.Comment;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@MultipartConfig
@WebServlet(name = "DeleteNewsServlet", value = "/DeleteNewsServlet")
public class DeleteCommentServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String str=request.getParameter("id");
        int id = Integer.parseInt(str);
        CommentService commentService=new CommentService();
        Map<String,Object> map=new HashMap<>();
        Gson gson =new Gson();
        int flag = commentService.delComment(id);
        if (flag>0){
            map.put("code",200);
            map.put("msg","删除成功");
        }else {
            map.put("code",500);
            map.put("msg","删除失败");
        }
        String json =gson.toJson(map);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    public void destroy() {
    }
}
